package com.mediacloud.app.newsmodule.fragment.navlive

import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.media.session.MediaController
import android.media.session.PlaybackState
import android.os.Bundle
import android.os.CountDownTimer
import android.os.IBinder
import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.OnScrollListener
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chinamcloud.audioserver.APSHelper
import com.chinamcloud.audioserver.AudioPlayerService
import com.chinamcloud.audioserver.MusicEntity
import com.chinamcloud.project.shanshipin.widget.AudioCenterLayoutManager
import com.eventTrack.CDPTrackReportManager
import com.eventTrack.TXReportManager
import com.eventTrack.TXReportManager.Companion.getVisibility
import com.facebook.drawee.view.SimpleDraweeView
import com.lzf.easyfloat.interfaces.OnPermissionResult
import com.lzf.easyfloat.permission.PermissionUtils.checkPermission
import com.mediacloud.app.adapter.ComponentRecyclerAdapter
import com.mediacloud.app.assembly.util.loadByFresco
import com.mediacloud.app.fbnavsk.navPaddingTopMatch
import com.mediacloud.app.model.component.ComponentItem
import com.mediacloud.app.model.news.ArticleItem
import com.mediacloud.app.model.news.ArticleListData
import com.mediacloud.app.model.news.CatalogItem
import com.mediacloud.app.model.news.ShowSwitch
import com.mediacloud.app.model.news.kt.TypeX
import com.mediacloud.app.nav2.fragment.HqyNavFragment
import com.mediacloud.app.nav2.utils.DateUtils
import com.mediacloud.app.newsmodule.BuildConfig
import com.mediacloud.app.newsmodule.R
import com.mediacloud.app.newsmodule.adaptor.component.BufferComponentContainer
import com.mediacloud.app.newsmodule.adaptor.component.ComponentHolder
import com.mediacloud.app.newsmodule.adaptor.component.IExposure
import com.mediacloud.app.newsmodule.fragment.newslist.TXRecommendFragment
import com.mediacloud.app.newsmodule.utils.EFFECTIVETIME
import com.mediacloud.app.newsmodule.utils.KillMusicUtils
import com.mediacloud.app.newsmodule.utils.encodeUrl
import com.mediacloud.app.reslib.enums.AppFactoryGlobalConfig
import com.mediacloud.app.reslib.enums.GlobalSwitch
import com.mediacloud.app.reslib.util.DataInvokeUtil
import com.mediacloud.app.user.utils.RxUtils
import com.utils.ExposurePoolService.Companion.getExecutorService
import com.utils.SystemServiceManager
import com.utils.TimeUtils
import com.utils.read.AudioFloatManager
import com.yoake.media.player.utils.auth.URLAuth
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.fragment_livebroadcast.componentRv
import kotlinx.android.synthetic.main.fragment_livebroadcast.freshLayout
import kotlinx.android.synthetic.main.fragment_livebroadcast.loadingBtn
import kotlinx.android.synthetic.main.fragment_livebroadcast.nameTv
import kotlinx.android.synthetic.main.fragment_livebroadcast.recyclerView
import kotlinx.android.synthetic.main.fragment_livebroadcast.scrollview
import kotlinx.android.synthetic.main.fragment_livebroadcast.toggleButton
import kotlinx.android.synthetic.main.fragment_livebroadcast.tvProgramName
import org.jetbrains.anko.support.v4.toast
import org.json.JSONArray
import org.json.JSONObject
import tv.danmaku.ijk.media.player.IMediaPlayer
import java.util.Collections
import kotlin.math.abs


/**
 * 听广播导航- 列表样式-广播直播指针播放样式
 */
@Suppress("IMPLICIT_CAST_TO_ANY")
class LiveBroadcastFragment : HqyNavFragment(),ServiceConnection,
    APSHelper.OnMediaStateChangeListener {
    override fun getLayoutResID(): Int {
        return R.layout.fragment_livebroadcast
    }

    private var navigateId: String? = null
    private var catalogItem: CatalogItem? = null
    private var firstVisibleItemPosition = -1
    private var currentIndex = 0
    private var scrollInit = false // 标记 RecyclerView的位置是否初始化完成
    private val adapter = Adapter()
    var adapterComponent: ComponentRecyclerAdapter<ComponentItem>? = null
    private var vmsCdnIv :String ?= ""
    private var vmsCdnKey :String ?=""
    var controller: MediaController? = null
    var helper: APSHelper? = null
    var currentChannel: ArticleItem? = null
    var hasRequestPermission:Boolean = false//是否弹过权限申请弹框

    val layoutManager by lazy {
        AudioCenterLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)

    }

    //正在播放的音频实体类
    var musicEntity: MusicEntity? = null
    var musicTask: String? = null

    //用来处理有直播垫片的时候
    var programList:MutableList<AudioProgramItem> = mutableListOf()
    val programMap =  mutableMapOf<String,MutableList<AudioProgramItem>>()
    var needLoopPlay = false
    var activeStop = false//服务会出现自己断掉的情况，标识以下如果不是自己断开的就重连一下
    var serviceDis = false//服务连接断开
    var playUrl:String?=null//记录需要重播的链接
    var currentTime = System.currentTimeMillis()

    //音频服务的事件回调
    var call = object : MediaController.Callback() {
        override fun onPlaybackStateChanged(state: PlaybackState?) {
            when (state?.state) {
                PlaybackState.STATE_NONE->{
                    if (System.currentTimeMillis() - currentTime > EFFECTIVETIME){
                        handleItem()
                        currentTime = System.currentTimeMillis()
                    }
                    loadingBtn.visibility = View.GONE
                    if (needLoopPlay){
                        toggleButton.isSelected = true
                    }else{
                        if (helper?.taskId == null || musicTask == helper?.taskId)
                            toggleButton.isSelected = false
                    }
                }
                PlaybackState.STATE_STOPPED,
                PlaybackState.STATE_PAUSED -> {
                    loadingBtn.visibility = View.GONE
                    if (needLoopPlay){
                        toggleButton.isSelected = true
                    }else{
                        if (helper?.taskId == null || musicTask == helper?.taskId)
                            toggleButton.isSelected = false
                    }
                    if (selectItem != null&& musicTask == helper?.taskId)
                      CDPTrackReportManager.getInstance().RadioEndPlay(selectItem,(System.currentTimeMillis() - currentTime)/1000)
                }
                PlaybackState.STATE_CONNECTING->{
                    if (helper?.taskId == null || musicTask == helper?.taskId)
                        loadingBtn.visibility = View.VISIBLE
                }

                PlaybackState.STATE_PLAYING -> {
                    currentTime = System.currentTimeMillis()
                    needLoopPlay = false
                    loadingBtn.visibility = View.GONE
                    toggleButton.isSelected = musicTask == helper?.taskId
                    if (musicTask == helper?.taskId)
                        currentChannel?.let {
                            CDPTrackReportManager.getInstance().RadioStartPlay(it)
                        }
                }

                PlaybackState.STATE_ERROR -> {
                    toast("出错了")
                }

                else -> {

                }
            }
        }

    }

    private fun bindService() {
        val intent = Intent(context, AudioPlayerService::class.java)
        requireContext().bindService(intent, this, 0)
        val intent2 = Intent(context, AudioPlayerService::class.java)
        requireContext().startService(intent2)
    }

    private fun unbindService() {
        activeStop = true
        controller?.unregisterCallback(call)
        helper?.removeMediaStateChangeListener(this)
        try {
            requireContext().unbindService(this)
        } catch (e: Exception) {
            e.printStackTrace()
        }
        APSHelper.serviceCollections.remove(this)
    }



    override fun initArgs() {
        super.initArgs()

        saveInstanceArguments = fragmentArguments
        navigateId = saveInstanceArguments?.getString("id") ?: ""
        catalogItem = saveInstanceArguments?.getParcelable("catalog") ?: CatalogItem()
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        navPaddingTopMatch()
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun initView() {
        vmsCdnIv = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_iv
        vmsCdnKey = AppFactoryGlobalConfig.ServerAppConfigInfo.OtherConfig.vms_cdn_key
        bindService()
        freshLayout.setEnableLoadMore(false)
        freshLayout.setOnRefreshListener { getData() }
        recyclerView.layoutManager = layoutManager
        val helper = LinearSnapHelper()
        helper.attachToRecyclerView(recyclerView)
        recyclerView.adapter = adapter
        adapter.setOnItemClickListener { adapter, _, position ->
            recyclerView.scrollToPosition(position)
            layoutManager.smoothScrollToPosition(recyclerView,RecyclerView.State(),position-1,position)
            if(TXReportManager.getInstance().firstTabInfo.tabName=="视听"){
                val item = adapter.getItem(position) as ArticleItem
                CDPTrackReportManager.getInstance().ShortVideoClick(item,adapter.data.indexOf(item))
            }
        }
        recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
            private val MAX_SCALE = 1.1f // 最大缩放比例

            override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
                super.onScrollStateChanged(recyclerView, newState)

                if (scrollInit && newState == RecyclerView.SCROLL_STATE_IDLE) {
                    val position = layoutManager.findFirstVisibleItemPosition()
                    val first = position % adapter.data.size
                    if (first != firstVisibleItemPosition) { //滚动停止后，如果取到的播放源和正在播放的不一致才设置播放数据
                        firstVisibleItemPosition = first
                        currentIndex = first + 2
                        resetTask()

                    }
                }
            }

            override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {

                val childCount = recyclerView.childCount
                val centerX = recyclerView.width / 2.0f
                for (i in 0 until childCount) {
                    val child = recyclerView.getChildAt(i)
                    val childCenterX = (child.left + child.right) / 2.0f

                    //距离中心位置的距离 最小0  最大 540
                    val centerXDistance = abs(centerX - childCenterX)
                    val itemWidth = resources.getDimensionPixelSize(R.dimen.dimen88)
                    if (centerXDistance > itemWidth) {
                        child.scaleX = 1f
                        child.scaleY = 1f
                    } else {
                        val ratio = centerXDistance * 1f / itemWidth
                        val scale = MAX_SCALE - ratio * (MAX_SCALE - 1)
                        child.scaleX = scale
                        child.pivotY = child.height.toFloat()
                        child.scaleY = scale
                    }


                }
            }
        })
        toggleButton.setOnClickListener {
            if (toggleButton.isSelected) {
                APSHelper.pause(requireContext())
            } else {
                resetTask()
            }
        }
        val manager = LinearLayoutManager(requireContext())
        componentRv.layoutManager = manager
        adapterComponent = ComponentRecyclerAdapter(requireContext())
        componentRv.adapter = adapterComponent

        scrollview.setOnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
            app_jhapp_home_subtab_content_imp()
        }

    }

    fun app_jhapp_home_subtab_content_imp(){
        componentRv.removeCallbacks(app_jhapp_home_subtab_content_impRunable)
        componentRv.postDelayed(app_jhapp_home_subtab_content_impRunable, TXReportManager.EXPOSURE_DELAY)
    }

    fun getElementList(componentItem:ComponentItem): MutableList<ArticleItem> {
        val list: MutableList<ArticleItem> = ArrayList()
        try {
            componentItem.orginDataObject.optJSONArray("element")?.let {
                for (i in 0 until it.length()) {
                    it.optJSONObject(i)?.let {
                        val item = ArticleItem.parse(it)
                        item.logo = it.optString("logo")
                        list.add(item)
                    }
                }
            }
        } catch (e: java.lang.Exception) {
            e.printStackTrace()
        }
        return list
    }
    private val app_jhapp_home_subtab_content_impRunable = Runnable {
        getExecutorService().execute {
            try {
                val childCount: Int = scrollview.getChildCount()
                for (i in 0 until childCount) {
                    val view: View = scrollview.getChildAt(i)
                    //判断View可见了才采集数据
                    if (getVisibility(view)) {
                        adapterComponent?.let{
                            for ((index, componentItem) in it.data.withIndex()) {
                                    val articleItemList =  getElementList(componentItem)
                                    var componentTitle = ""
                                    if (componentItem != null) {
                                        if (!TextUtils.isEmpty(componentItem.getTitle()) && !componentItem.getTitle().contains("https")) {
                                            componentTitle = componentItem.getTitle()
                                        }
                                        if (TextUtils.isEmpty(componentTitle)) {
                                            if (TextUtils.isEmpty(componentItem.getSname())) {
                                                if (!TextUtils.isEmpty(
                                                        componentItem.getName()
                                                    )
                                                ) {
                                                    componentTitle = componentItem.getName()
                                                }
                                            } else {
                                                componentTitle = componentItem.getSname()
                                            }
                                        }
                                    }
                                    for (k in articleItemList?.indices!!) {
                                        val article = articleItemList[k]
                                        CDPTrackReportManager.getInstance().ShortVideoExpose(article,k,null,componentTitle)

                                    }
                            }

                        }

                    }
                }
            } catch (e: java.lang.Exception) {
                e.printStackTrace()
            }
        }
    }


    override fun choosed() {
        super.choosed()
        if (currentChannel == null)
            getData()
    }
    fun resetTask() {
        programList.clear()
        musicTask = null
        musicEntity = null
        currentChannel = adapter.getItem(currentIndex)
        if (programMap[currentChannel?.vid]!= null){
            programList.addAll(programMap[currentChannel?.vid]!!)
        }
        if (programList.isNotEmpty()){
            handleItem()
        }else
            getLiveProgramInfo(currentChannel?.vid)
    }


    var selectItem:ArticleItem?=null
    private fun play(title: String? = null,url:String?=null) {
        playUrl = url
        currentChannel?.let {item->
            if (selectItem != null)
              CDPTrackReportManager.getInstance().RadioEndPlay(selectItem,(System.currentTimeMillis() - currentTime)/1000)
            nameTv.text = item.title
            tvProgramName.text =  "正在播放:${item.title}"
            musicTask = "${item.id}"
            musicEntity = MusicEntity(title ?: item.title, url ?: getUrl(item))
            KillMusicUtils.hidAudioExcludeFM(requireContext())
            APSHelper.play(requireContext(), musicTask!!, musicEntity!!)
            showFloatController(title ?: item.title)
            selectItem = item
        }
    }

    var mNetType = 0
    private fun checkNetType(): Boolean {
//        if (!checkNetType()){
//            return
//        }
//        val isAutoPlay = MMKV.defaultMMKV().decodeBool(XKey.AUTO_PLAY, false)
//        if (!isAutoPlay && mNetType != ConnectivityManager.TYPE_WIFI) {
//            return
//        }
        val cm = SystemServiceManager.getConnectivityManager(context)
        val networkInfo = cm.activeNetworkInfo
        if (networkInfo != null && networkInfo.isAvailable) {
            mNetType = networkInfo.type
            return true
        }
        return false
    }
    private fun getUrl(articleItem: ArticleItem?): String {
        val appCustomParams = articleItem?.appCustomParams
        appCustomParams?.let{
            val jsonObject = JSONObject(it)
            val movie = jsonObject.optJSONObject("movie")
            val path = movie.optString("livePath")
            val liveDomain = movie.optString("liveDomain")
            val liveId = movie.optString("liveId")
            val txFlag = movie.optString("txFlag")
            if (txFlag == "1") {
                return encodeUrl(liveDomain,liveId)
            }else{
                val audio = articleItem?.audio ?: return ""
                val objectAll = JSONObject(audio)
                return try {
                    val pcArray: JSONArray = objectAll.optJSONArray("ANDROID")
                    val cdnConfigEncrypt = objectAll.optString("cdnConfigEncrypt")
                    if (pcArray.length() != 0) {
                        URLAuth.encode(
                            URLAuth.EncrptMode(cdnConfigEncrypt, vmsCdnKey, vmsCdnIv),
                            pcArray.optJSONObject(0).optString("url"),
                            true,
                            false
                        )
                    } else {
                        ""
                    }
                } catch (e: Exception) {
                    ""
                }
            }
        }
       return ""
    }

    //显示悬浮窗
    private fun showFloatController(title: String) {
        AudioFloatManager.getInstance(requireContext()).article = currentChannel
        recyclerView.postDelayed({
            //延迟550毫秒防止关闭动画还没结束又显示导致悬浮窗中的控件资源释放了的问题
            if (checkPermission(requireContext())) { //有悬浮窗权限直接弹出
                AudioFloatManager.getInstance(requireContext()).show(1000, title)
            } else { //申请悬浮窗权限
                if (hasRequestPermission) return@postDelayed
                AudioFloatManager.showPermissionAsk(requireActivity(),
                    object : OnPermissionResult {
                        override fun permissionResult(isOpen: Boolean) {
                            if (isOpen) {
                                try {
                                    AudioFloatManager.getInstance(requireContext())
                                        .show(1000, title)
                                } catch (e: Exception) {
                                    e.printStackTrace()
                                }
                            }else{
                                hasRequestPermission = true
                            }
                        }
                    })
            }
        }, 550)
    }

    private fun getData() {
        DataInvokeUtil.ziMeiTiApi
            .getContentList(navigateId, 1, 100, "android")
            .map {
                val result = ArticleListData()
                result.readFromJson(it)
                result
            }
            .onErrorReturn { null }
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(object : Observer<ArticleListData> {
                override fun onSubscribe(d: Disposable) {

                }

                override fun onError(e: Throwable) {

                }

                override fun onComplete() {

                }

                override fun onNext(t: ArticleListData) {
                    freshLayout.finishRefresh()
                    adapter.setNewData(t.articleList)
                    adapterComponent?.data = t.componentItems
                    adapterComponent?.notifyItemRangeChanged(0, t.componentItems.size)
                    val length = adapter.data.size
                    if (length > 0) {
                        currentIndex = 0
                        currentChannel = adapter.data[0]
                        currentChannel?.let {
                            nameTv.text = it.title
                            tvProgramName.text =  "正在播放:${it.title}"
                        }
                        val per = Int.MAX_VALUE / 2 / length
                        val targetPosition = length * per
                        recyclerView.scrollToPosition(targetPosition)
                        layoutManager.smoothScrollToPosition(recyclerView,RecyclerView.State(),targetPosition-1,targetPosition)
                        recyclerView.postDelayed({
                            scrollInit = true
                        }, 1000)
                        getLiveProgramInfo(currentChannel?.vid)
                    }
                }
            })

    }


   @SuppressLint("CheckResult")
   fun getLiveProgramInfo(sourceId: String?) {
       val today = DateUtils.getDate()
       val json = HashMap<String, Any?>()
       json["tenantId"] = getString(R.string.tenantid)//租户ID
       json["sourceId"] = sourceId//信源ID
       json["day"] = today
       json["source_type"] = 2

       DataInvokeUtil.getZiMeiTiApi()
           .getProgramInfo(json)
           .compose(RxUtils.schedulersTransformer())
           .subscribe({
               var data: JSONObject? = null
               if (it.optBoolean("state")) {
                   val result = it.optJSONObject("result")
                   if (result != null) {
                       data = result.optJSONObject("data")
                       data?.optJSONArray(today)?.let{
                           programList.clear()
                           for (i in 0 until it.length()){
                               val jsonObject = it.optJSONObject(i)
                               val endDateTime = jsonObject.optString("endDateTime")
                               val startDateTime = jsonObject.optString("startDateTime")
                               val url = jsonObject.optString("url")
                               programList.add(AudioProgramItem(TimeUtils.DEFAULT_FORMAT.parse(startDateTime)?.time,
                                  TimeUtils.DEFAULT_FORMAT.parse(endDateTime)?.time,url))
                           }
                           programMap[sourceId!!] = programList
                           if (programList.isNotEmpty())
                              handleItem()
                           else play()
                       }?:play()
                   }
               }

           }, {
              play()
           }, {

           }, {

           })
   }



    var timer:CountDownTimer?=null


    @SuppressLint("CheckResult")
    fun handleItem(){
        var playItem:AudioProgramItem ? = null
        clear()
        if (programList.size > 0){
            if (programList[0].startTime!! > System.currentTimeMillis()){
                //1.未开始 直接播正常流，然后倒计时去处理节目单
                play()
                timer = object:CountDownTimer(programList[0].startTime!!  - System.currentTimeMillis(),1000){
                    override fun onTick(p0: Long) {

                    }

                    override fun onFinish() {
                        handleItem()
                    }

                }
                timer?.start()
            }else if (programList[programList.size-1].endTime!! < System.currentTimeMillis()){
                //4.播完节目单，继续播正常流
                play()
            } else {
                for ((i, audioProgramItem) in programList.withIndex()) {
                    playItem = audioProgramItem
                    if (audioProgramItem.startTime!! > System.currentTimeMillis()) {
                        //3.节目单中间的时间播正常流
                        play()
                        timer = object:CountDownTimer(audioProgramItem.startTime!!  - System.currentTimeMillis(),1000){
                            override fun onTick(p0: Long) {

                            }

                            override fun onFinish() {
                                handleItem()
                            }

                        }
                        timer?.start()
                        break
                    } else if (audioProgramItem.endTime!! >= System.currentTimeMillis()) {
                        //2.节目单开始了，播节目单流
                        play(null, playItem?.playUrl)
                        timer = object : CountDownTimer(audioProgramItem.endTime!! - System.currentTimeMillis(), 1000) {
                            override fun onTick(p0: Long) {

                            }

                            override fun onFinish() {
                                handleItem()
                            }

                        }
                        timer?.start()
                        break
                    }
                }
            }

        }else{
            play()
        }
    }

    fun clear(){
        timer?.cancel()
        timer = null
    }
    //频道列表适配器
    class Adapter : BaseQuickAdapter<ArticleItem, BaseViewHolder>(R.layout.item_broadcast) {
        override fun convert(helper: BaseViewHolder, item: ArticleItem?) {
            val logoIv: SimpleDraweeView = helper.getView(R.id.ivBroad)
            logoIv.loadByFresco(item?.logo)
            if(TXReportManager.getInstance().firstTabInfo.tabName=="视听"){
                CDPTrackReportManager.getInstance().ShortVideoExpose(item!!,data.indexOf(item))
            }
        }

        override fun getItem(position: Int): ArticleItem? {
            return if (mData.size > 0)
                mData[position % mData.size]
            else null
        }

        override fun getItemCount(): Int {
            return Int.MAX_VALUE
        }

        override fun getItemViewType(position: Int): Int {
            var count = headerLayoutCount + data.size
            if (count <= 0) {
                count = 1
            }
            return super.getItemViewType(position % count)
        }


    }


    override fun onServiceConnected(name: ComponentName?, iBinder: IBinder?) {
        if (iBinder is AudioPlayerService.ServiceBinder) {
            APSHelper.serviceCollections.add(this)
            try {
                helper = iBinder.service.helper
                helper?.addMediaStateChangeListener(this)
                controller = MediaController(requireContext(), helper!!.mediaSession!!.sessionToken)
                controller?.registerCallback(call)
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

    override fun onServiceDisconnected(name: ComponentName?) {
        Log.e("mmm","${name?.packageName}")
        serviceDis = true
    }

    override fun onResume() {
        super.onResume()
        if (!activeStop && serviceDis){
            bindService()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        clear()
        unbindService()
    }

    override fun onBufferingUpdate(mediaPlayer: IMediaPlayer?, percent: Int) {

    }

    override fun onCompletion(mediaPlayer: IMediaPlayer?) {
        Log.e("mmm","complete")
        if (playUrl != null){
            needLoopPlay = true
            APSHelper.pause(requireContext())
            recyclerView.postDelayed({
                handleItem()
            },500)
        }

    }

    override fun onPrepared(mediaPlayer: IMediaPlayer?) {

    }

    override fun onTimeOffCountDown(millisUntilFinished: Long) {

    }

    override fun onTimeOffCountDownFinish() {

    }

    override fun onUpdateProgress(mediaPlayer: IMediaPlayer?) {

    }


}